aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/article/[slug].tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-11-07 16:55:58 +0100
committerArmand Philippot <git@armandphilippot.com>2023-11-11 18:15:27 +0100
commitbd9c9ae7e2ae973969569dd434836de9f38b07d4 (patch)
tree84905097c4f2c2db36794c20910e3893189a65e1 /src/pages/article/[slug].tsx
parentc9c1c90b30e243563bb4f731da15b3fe657556d2 (diff)
refactor(components): split Comment component into 3 components
* add ApprovedComment, PendingComment and ReplyCommentForm components * let consumer handle reply form visibility * move structured data into article page (each article already has the comments data and already handle json ltd schema so I prefered to move the schema in the final consumer instead of adding a script element foreach comment)
Diffstat (limited to 'src/pages/article/[slug].tsx')
-rw-r--r--src/pages/article/[slug].tsx32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/pages/article/[slug].tsx b/src/pages/article/[slug].tsx
index d1e680c..449af8d 100644
--- a/src/pages/article/[slug].tsx
+++ b/src/pages/article/[slug].tsx
@@ -7,6 +7,7 @@ import { useRouter } from 'next/router';
import Script from 'next/script';
import type { HTMLAttributes } from 'react';
import { useIntl } from 'react-intl';
+import type { Comment as CommentSchema, WithContext } from 'schema-dts';
import {
ButtonLink,
getLayout,
@@ -217,10 +218,39 @@ const ArticlePage: NextPageWithLayout<ArticlePageProps> = ({
slug,
title,
});
+ const commentsSchema: WithContext<CommentSchema>[] = commentsData
+ ? commentsData.map((comment) => {
+ return {
+ '@context': 'https://schema.org',
+ '@id': `${website.url}/#comment-${comment.id}`,
+ '@type': 'Comment',
+ parentItem: comment.parentId
+ ? { '@id': `${website.url}/#comment-${comment.parentId}` }
+ : undefined,
+ about: { '@type': 'Article', '@id': `${website.url}/#article` },
+ author: {
+ '@type': 'Person',
+ name: comment.meta.author.name,
+ image: comment.meta.author.avatar?.src,
+ url: comment.meta.author.website,
+ },
+ creator: {
+ '@type': 'Person',
+ name: comment.meta.author.name,
+ image: comment.meta.author.avatar?.src,
+ url: comment.meta.author.website,
+ },
+ dateCreated: comment.meta.date,
+ datePublished: comment.meta.date,
+ text: comment.content,
+ };
+ })
+ : [];
const schemaJsonLd = getSchemaJson([
webpageSchema,
blogSchema,
blogPostSchema,
+ ...commentsSchema,
]);
const lineNumbersClassName = className
@@ -272,7 +302,7 @@ const ArticlePage: NextPageWithLayout<ArticlePageProps> = ({
</Head>
<Script
// eslint-disable-next-line react/jsx-no-literals -- Id allowed
- id="schema-project"
+ id="schema-article"
type="application/ld+json"
// eslint-disable-next-line react/no-danger -- Necessary for schema
dangerouslySetInnerHTML={{ __html: JSON.stringify(schemaJsonLd) }}